﻿
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">   
    <link rel="stylesheet" href="~/lib/css/font.css">
    <link rel="stylesheet" href="~/lib/css/xadmin.css">
    <script src="~/lib/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/lib/js/xadmin.js"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">管理员管理</a>           
            <a>
                <cite>管理员列表</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="username" id="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                               <select name="RoleId" lay-filter="aihao" id="userroles">
                                    <option value="">--员工身份--</option>
                                    @foreach (var item in ViewBag.RolesName)
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                               </select>                               
                            </div>
                            <div class="layui-inline layui-show-xs-block">                                
                                <button class="layui-btn" data-type="reload"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">                        
                        <button onclick="adduser()" class="layui-btn" ><i class="layui-icon"></i>添加后台用户</button>
                    </div>                    
                    <script type="text/html" id="barDemo">
                        <ul>                            
                            <li class="td-manage">
                                <a lay-event="delData" href="javascript:;" title="冻结与解冻用户" style="padding-right:10px">
                                    <i class="layui-icon">&#xe6b1;</i>
                                </a>
                                <a lay-event="edit"  title="修改权限" href="javascript:;" style="padding-right:10px">
                                    <i class="layui-icon">&#xe642;</i>
                                </a>
                                <a lay-event="reset" title="重置密码" href="javascript:;" style="padding-right:10px">
                                    <i class="layui-icon">&#xe631;</i>
                                </a>                                
                            </li>
                        </ul>
                    </script>
                    <div class="layui-card-body ">
                        <table id="demo" lay-filter="demoX" class="layui-table layui-form"></table>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>    
</body>
<script>
        var loadCurr = false; //等于0表示重载当前页
        layui.use(['table', 'layer', 'form'], function () {
            $ = layui.jquery;
            var layer = layui.layer, table = layui.table, form = layui.form;
            //第一个实例
            var tableIns = table.render({
                elem: '#demo'
                , height: 500
                , url: '/adminList/Search'
                , page: true//开启分页
                , toolbar: '#toolbarDemo'
                , cols: [[ //表头                   
                      { field: 'LoginName', title: '姓名', width: 120, align: 'center' }
                    , { field: 'ProtectMTel', title: '手机号码', width: 150, align: 'center' }
                    , { field: 'ProtectEMail', title: '电子邮箱', width: 150, align: 'center' }
                    , { field: 'CreateTime', title: '加入时间', width: 180, align: 'center' }                    
                    , { field: 'IsLockout', title: '状态', width: 140, align: 'center'}
                    , { field: 'right', align: 'center', toolbar: '#barDemo', title: '操作', width: 185 }
                ]],
                id: 'testReload',
                done: function (res, curr, count) {
                    loadCurr = false;
                }
            });
            //行内工具栏事件
            table.on('tool(demoX)', function (obj) {
                var data = obj.data;
                //禁用管理员开始
                if (obj.event === 'delData') {                   
                    layer.confirm('确定冻结此用户吗？',function (index) {
                        $.post("/adminList/Forbidden", { id: data.Id }, function (res) {
                            if (res.success) {
                                layer.msg(res.msg, { icon: 1, time: 1500 }, function () {
                                    window.location.reload();
                                });
                            }
                            else {
                                layer.msg(res.msg, { icon: 1, time: 1500 });
                            }
                        }, "json");
                        layer.close(index);
                    });                   
                    
                }
                //禁用管理员结束
                //修改员工省份信息开始
                if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title:"修改员工身份",
                        area: ["600px", "400px"],
                        content: "/adminList/edit?id=" + data.Id,
                        end: function () {
                            window.location.reload();
                        }
                    });
                }
                //修改员工省份信息结束
                //重置密码开始
                if (obj.event === 'reset') {
                    layer.confirm('确定重置此员工密码吗？', function (index) {
                        $.post("/adminList/reset", { id: data.Id }, function (res) {
                            if (res.success) {
                                layer.msg(res.msg, { icon: 1, time: 1500 }, function () {
                                    window.location.reload();
                                });
                            }
                            else {
                                layer.msg(res.msg, { icon: 2, time: 2000 });
                            }
                        }, "json");
                        layer.close(index);
                    });
                }
                //重置密码结束
            });
            //条件区事件框架begin
            active = {
                reload: function () { //加载当前页
                    alert("5")
                    if (loadCurr) {
                        table.reload('testReload', {
                            where: {
                                name: $("#username").val()                              

                            }
                        });
                    }
                    else {//加载第 1 页
                        table.reload('testReload', {
                            page: {
                                curr: 1
                            },
                            where: {
                                name: $("#username").val()

                            }
                        });
                    }
                }
            };
        });
    
        layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        $ = layui.jquery;

        // 监听全选
        form.on('checkbox(checkall)', function(data){

          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#adduser' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });


      });
</script>
</html>
<script>
    //点击添加管理员按钮
    function adduser() {        
        layer.open({
            type: 2,
            area: ["600px", "400px"],
            content: "/AddAdmin/Index",
            end: function () {
                window.location.reload();
            }
        });        
    }
</script>


